using System;
using System.Collections.Generic;
using System.Text;

using miciv;
using micivCore.Level;

namespace micivCore.DataSource
{
    public class LevelConfigDataSource : DataSourceBase<LevelSettings>
    {
        protected LevelSettings m_levelSettings;
        public LevelSettings LevelSettings
        {
            get
            {
                return this.m_levelSettings;
            }
            set
            {
                if (value != this.m_levelSettings)
                {
                    this.m_levelSettings = value;
                }
            }
        }

        public LevelConfigDataSource()
        {

        }

        override public T GetData<T>(int _sSourceIndex, string _strFieldName)
        {
            if ((null != this.LevelSettings) && (this.LevelSettings.MaxPlayers > _sSourceIndex))
            {
                switch (_strFieldName)
                {
                    case "partyname":
                    {
                        return this.LevelSettings.LevelName as T;
                    }
                    case "playername":
                    {
                        return this.LevelSettings.PlayerDescs[_sSourceIndex].NickName as T;
                    }
                    case "playerfaction":
                    {
                        return this.LevelSettings.PlayerDescs[_sSourceIndex].Faction.ID as T;
                    }
                }
            }
            return default(T);
        }

        override public int Count
        {
            get
            {
                return (null != this.LevelSettings) ? this.LevelSettings.MaxPlayers : 0;
            }
        }
    }
}
